<template>
	<view class="address">
		<cl-toast ref="toast"></cl-toast>

		<cl-form ref="form" :model.sync="form" :rules="rules" :show-message="false" :label-position="labelAlign"
			:label-width="labelWidth">

			<cl-form-item label="所属账户" prop="suoshuzhanghuai23">
				<cl-input :disabled="true" v-model="form.suoshuzhanghuai23"></cl-input>
			</cl-form-item>

			<cl-form-item label="可用余额" prop="shijiyuerqx0">
				<cl-input :disabled="true" v-model="form.shijiyuerqx0"></cl-input>
			</cl-form-item>
			<cl-form-item label="冻结金额" prop="dongjiejineo8rd">
				<cl-input :disabled="true" v-model="form.dongjiejineo8rd"></cl-input>
			</cl-form-item>
			<cl-form-item label="提现金额" prop="caozuojine8c03">
				<cl-input placeholder="请填写提现金额" v-model="form.caozuojine8c03"></cl-input>
			</cl-form-item>
			<cl-form-item label="提现银行" prop="tixianyinxing644l">
				<cl-input placeholder="请填写提现银行" v-model="form.tixianyinxing644l"></cl-input>
			</cl-form-item>
			<cl-form-item label="银行账号" prop="yinxingzhanghaor73g">
				<cl-input placeholder="请填写银行账号" v-model="form.yinxingzhanghaor73g"></cl-input>
			</cl-form-item>
		</cl-form>

		<view class="footer">
			<cl-row :gutter="20">
				<cl-button type="primary" fill @tap="onSubmit">确认提交</cl-button>
			</cl-row>
		</view>

	</view>
</template>

<script>
	import api from "@/api/api"
	import helper from "@/utils/helper"
	import {
		isArray
	} from "cl-uni/utils";
	export default {
		components: {},
		data() {
			return {
				form: {
					caozuojine8c03: 0,
					suoshuzhanghuai23: '',
					shijiyuerqx0:0,
					dongjiejineo8rd:0,
				},
				rules: {
					caozuojine8c03: {
						required: true,
						message: "操作金额不能为空"
					},
					tixianyinxing644l: {
						required: true,
						message: "提现银行不能为空"
					},
					yinxingzhanghaor73g: {
						required: true,
						message: "银行账号不能为空"
					},
				},
				labelAlign: "right",
				labelWidth: "180rpx",
				isRule: true,
				showMessage: true,
				disabled: false,
				userInfo:{},
				account:{}
			};
		},
		onLoad: function(options) {
			this.loadItem()
		},
		mounted() {

		},
		methods: {

			loadItem() {
				let that = this;
				this.userInfo = uni.getStorageSync('userInfo');
				this.$http.post(api.getShopAccount, {
					sessionKey: uni.getStorageSync('accessToken'),
					userLoginId: that.userInfo.userLoginId
				}).then(function(res) {
					if (res.code == "0") {
						that.account = res.result
						that.form.suoshuzhanghuai23 = res.result.suoshuzhanghao3wpo
						that.form.shijiyuerqx0 =  res.result.shijiyuerqx0
						that.form.dongjiejineo8rd = res.result.dongjiejineo8rd
					}
				});
			},

			onSubmit() {
				let that = this
				that.$refs["form"].validate((valid, errors) => {
					if (valid) {
						let apiUrl = api.createShopAccountCharge
						console.log(that.form.caozuojine8c03,that.form.shijiyuerqx0);
						if(that.form.caozuojine8c03>that.form.shijiyuerqx0){
							that.$refs["toast"].open("提现金额不能大于账户余额,当前余额为:"+that.form.shijiyuerqx0);
							return false;
						}
						if(that.form.caozuojine8c03<1){
							that.$refs["toast"].open("提现金额不能小于1元!");
							return false;
						}
						that.$http.post(apiUrl, that.form).then(res => {
							if (res.code == "0") {
								that.$refs["toast"].open("提交成功");
								uni.switchTab({
									url: '/pages/tabbar/firstpage/firstpage'
								});
							} else {
								that.$refs["toast"].open(res.message);
							}
						});
					} else {
						that.$refs["toast"].open(errors[0].message);
					}
				});
			},
		}
	};
</script>

<style lang="scss" scoped>
	.address {
		border-top: 1rpx solid #eee;
		;
		background-color: #fff;
		padding: 20rpx;
		padding-bottom: calc(90rpx + env(safe-area-inset-bottom));

		/deep/.cl-radio {
			height: 50rpx;
			line-height: 50rpx;
			font-size: 26rpx;

		}

		/deep/.cl-radio.is-border {
			padding: 0 20rpx;
		}

		.footer {
			position: fixed;
			bottom: 0;
			left: 0;
			width: 100%;
			background-color: #fff;
			z-index: 9;
			padding: 10rpx 20rpx;
			box-sizing: border-box;
			border-top: 1rpx solid #eee;
			padding-bottom: calc(env(safe-area-inset-bottom) + 10rpx);
		}

	}
</style>